;function Animate(elems) {

  // 元素集合，如果是单一dom元素，用数组表示
  var elems = elems.length ? elems : [elems],

    i, len = elems.length,

    // 新建一个队列对象
    q = Queue(),

    // 获取时间戳
    _newTime = function() {
        return +new Date();
    },

    // 获取元素css值
    _getStyle = function(elem,attr) {

      var value = window.getComputedStyle ? getComputedStyle(elem,null)[attr] : 
          elem.currentStyle[attr];
    
      if(attr == 'opacity') {
        value = (+value) * 100;
      }else {
        value = +value.replace(/pt|px/,'');
      }

      return value;
    },
    // 优化定时器
    requestNewAnimationFrame = window.requestAnimationFrame
      || window.webkitRequestAnimationFrame 
      || window.oRequestAnimationFrame 
      || window.mozRequestAnimationFrame 
      || window.msRequestAnimationFrame
      || window.setTimeout,
      
    cancelRequestNewAnimationFrame = window.cancelRequestAnimationFrame
      || window.cancelAnimationFrame
      || window.webkitCancelAnimationFrame
      || window.webkitCancelRequestAnimationFrame
      || window.mozCancelRequestAnimationFrame
      || window.oCancelRequestAnimationFrame
      || window.msCancelRequestAnimationFrame
      || clearTimeout;

  
  return {
    delay: q.delay,
    animate: function(options,time,callback) {

       // 执行动画函数
      var _animate = function(next) {


        //属性， 目标值，原来的值，长度差
        var key, target, original, result, spaceLength;

        // 开始时间，当前时间，间隔时差
        var startTime = _newTime(), nowTime, spaceTime;

        // 各个元素属性初始值设定
        var initValue = (function() {
          var initArr = [];
          for(i=0; i<len; i++) {
            for(key in options) {
              initArr[i+key] = _getStyle(elems[i],key);
            }

          }
          return initArr;
        })();

        // 循环执行函数
        var task = function() {
          // 动画完成指标
          var finded = true;

          nowTime = _newTime();

          spaceTime = nowTime - startTime;

          for(i=0; i<len; i++) {
            var elem = elems[i];

            for(key in options) {

              target = options[key];

              original = initValue[i+key];

              spaceLength = target - original;

              if( spaceTime < time ) {
                finded = false;
                result = original + spaceTime/time * spaceLength;
                //elem.style[key] = key == 'opacity' ? result/100 : result + 'px';
                if( key == 'opacity' ) {
                  elem.style[key] = result/100;
                  elem.style.filter = 'alpha(opacity='+result+')';
                }else {
                  elem.style[key] = result + 'px';
                }
              }else {
                //elem.style[key] = key == 'opacity' ? target/100 : target + 'px';
                if( key == 'opacity' ) {
                  elem.style[key] = target/100;
                  elem.style.filter = 'alpha(opacity='+target+')';
                }else {
                  elem.style[key] = target + 'px';
                }
              }


            }
          }

          if(finded) {

           // clearInterval(timerId);
            cancelRequestNewAnimationFrame(timerId)
            timerId = null;
            // 队列继续
            next();

            if(callback && typeof callback == 'function') {
              callback();
            }
          }else {
            timerId = requestNewAnimationFrame(task,15);
          }

        };

        //var timerId = setInterval(task,15);
        var timerId = requestNewAnimationFrame(task,15);

       }
       // 入队自动执行第一个队列内的函数
       q.queue(_animate);

       return this;
    }
  }
}